﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;
using Antu.Core.DataAccess;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZJ_BCKJBInfoControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            Label txt征收部门 = (Label)FindControl("lbl征收部门");
            Label txt征收实施单位 = (Label)FindControl("lbl征收实施单位");
            Label txt开户银行 = (Label)FindControl("lbl开户银行");
            Label txt银行账号 = (Label)FindControl("lbl银行账号");
            Label txt评估总补偿款 = (Label)FindControl("lbl评估总补偿款");
            Label txt到账金额 = (Label)FindControl("lbl到账金额");
            Label txt划转金额 = (Label)FindControl("lbl划转金额");
            Label txt余额 = (Label)FindControl("lbl余额");
            Label txt时间 = (Label)FindControl("lbl时间");
            Label txt备注 = (Label)FindControl("lbl备注");
            TextBox txtPNID = (TextBox)FindControl("txtPNID");
            TextBox txtID = (TextBox)FindControl("txtID");
            Label LXH = (Label)FindControl("LXH");
            TextBox TextBox1 = (TextBox)FindControl("TextBox1");
            string strPid = base.Page.Request["PID"];
            string strid = base.Page.Request["ID"];
            if (!string.IsNullOrEmpty(strPid))
            {
                if (string.IsNullOrEmpty(txtPNID.Text.Trim())) { txtPNID.Text = strPid; }
                EluZSProvider.Project project = _EluZSDataProvider.GetProjectXX(strPid);
                if (string.IsNullOrEmpty(LXH.Text.Trim())) { LXH.Text = project.立项号; }
                if (string.IsNullOrEmpty(txt征收部门.Text.Trim())) { txt征收部门.Text = project.征收部门; }
                if (string.IsNullOrEmpty(txt征收实施单位.Text.Trim())) { txt征收实施单位.Text = project.征收实施单位; }
            }
            if (!string.IsNullOrEmpty(strid))
            {
                if (string.IsNullOrEmpty(txtID.Text.Trim())) { txtID.Text = strid; }
                EluZSProvider.Bcbasicinfo bcbasicinfo = _EluZSDataProvider.GetBcbasicinfo(strid);
                txt开户银行.Text = bcbasicinfo.开户银行; 
                txt银行账号.Text = bcbasicinfo.银行账号; 
                txt评估总补偿款.Text = bcbasicinfo.评估总补偿款;

                txt到账金额.Text = _EluZSDataProvider.GetString("select sum(to_number(nvl(replace(到账金额, '\', ''), 0))) from zs_new_money where bid='" + strid + "'");
                txt划转金额.Text = _EluZSDataProvider.GetString("select sum(to_number(nvl(replace(划转金额, '\', ''), 0))) from zs_change_money where bid='" + strid + "'");
                string sql = @"select (to_number(nvl((select sum(to_number(nvl(replace(到账金额, '\', ''), 0)))
                                from zs_new_money
                               where bid = '" + strid + @"'),
                              0)) -
               to_number(nvl((select sum(to_number(nvl(replace(划转金额, '\', ''), 0)))
                                from zs_change_money
                               where bid ='" + strid + @"'),
                              0)))
          from dual";
                txt余额.Text = _EluZSDataProvider.GetString(sql);               
                if (bcbasicinfo.时间.HasValue) { txt时间.Text = bcbasicinfo.时间.Value.ToShortDateString(); }
                txt备注.Text = bcbasicinfo.备注; 
                txtPNID.Text = bcbasicinfo.PNID; 
                txtID.Text = bcbasicinfo.ID; 
            }
            if (string.IsNullOrEmpty(TextBox1.Text.Trim())) {
                TextBox1.Text = _EluZSDataProvider.GetISPCHZ(strPid);
            }
        }
    }
}


